package com.difsonapps.android.marker;

import com.difsonapps.android.marker.beans.Album;
import com.difsonapps.android.marker.beans.User;
import com.difsonapps.android.marker.fragments.AlbumsFragment;
import com.difsonapps.android.marker.fragments.PhotosFragment;
import com.difsonapps.android.marker.fragments.ProfileFragment;

import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class ProfileActivity extends Activity {
	User user;//The user that the profile is shown here
	
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_profile);
		getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.main_color)));
		
		user = new User();
		user.setFirstname("Fr");
		user.setLastname("Wdji");
		user.setId(2);
		user.setPicture("1360671997Lighthouse.jpg");
		//TODO get the user in the intent
		Intent intent = this.getIntent(); 
		user = intent.getParcelableExtra("user");
		
		
		showFragment(ProfileFragment.newInstance(user));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.profile, menu);
		return true;
	}
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar actions click
        switch (item.getItemId()) {
        case R.id.action_settings:
        	toast("Settings");
            return true;
        case R.id.profile_item:
        	showFragment(ProfileFragment.newInstance(user));
            return true;
        case R.id.photos_item:
        	showFragment(AlbumsFragment.newInstance(user));
            return true;
        case R.id.videos_item:
        	toast("Videos");
            return true;
        case R.id.friends_item:
        	toast("Friends");
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
	
    public void showPhotosFragment(Album album){
    	Fragment fragment = PhotosFragment.newInstance(album);
    	showFragment(fragment);
    }
    
	private void showFragment(Fragment fragment){
    	FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.profile_frame_container, fragment).commit();
        
    }
	private void toast(String text){
		Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
	}

}
